<template>
  <div class="confirmcart">
    <div class="cartheader">
      <div class="container w">
        <div class="header-logo"></div>
        <div class="header-title">
          <h2>确认订单</h2>
          <p>确认订单后，就可以付款了哦</p>
        </div>
      </div>
    </div>
    <div class="hr-20"></div>
    <Address ref="address"></Address>
    <div class="hr-20"></div>
    <div class="hr-20"></div>
    <div class="order-detail-area w" style="width: 1121px">
      <div class="order-detail clearfix">
        <div class="order-list" v-if="carts != []">
          <div
            class="order-list-detail"
            v-for="(item, index) in carts.cart"
            :key="index"
          >
            <div class="order-main clearfix">
              <a style="cursor: default" class="p-img">
                <img
                  :src="`https://img11.360buyimg.com/n7/${cartimg[index][0]}`"
                />
              </a>
              <ul class="">
                <li>
                  <a style="cursor: default" class="p-name">
                    {{ item.jixing }}
                    {{ item.color == "0" ? " " : item.color }}
                    {{ item.version == "0" ? "" : item.version }}</a
                  >
                </li>
                <li>x{{ item.buynumber }}</li>
                <li class="p-price">¥&nbsp;{{ item.price }}.00</li>
              </ul>
            </div>
          </div>
        </div>
        <div>
          <div class="order-submit">
            <div class="order-submit-info">
              <div class="order-submit-price">
                应付金额：<b
                  >¥<span>{{ carts.price }}</span></b
                >
              </div>
              <div class="order-submit-address">
                <ul>
                  <li>
                    <label>配送至：</label>
                    <p v-if="nowadd != '' && nowadd != undefined">
                      <span
                        >{{ nowadd.rvregion.province.value }}
                        {{ nowadd.rvregion.city.value }}
                        {{ nowadd.rvregion.area.value }}
                        {{ nowadd.rvregion.deaddress }}</span
                      >
                    </p>
                    <p v-show="nowadd == '' || nowadd == undefined">
                      <span>没有地址哦~</span>
                    </p>
                  </li>
                  <li>
                    <p v-if="nowadd != '' && nowadd != undefined">
                      <span>{{ nowadd.rvname }} {{ nowadd.rvphone }}</span>
                    </p>
                  </li>
                </ul>
              </div>
              <div class="clearfix">
                <a
                  href="javascript:;"
                  class="order-submit-btn"
                  @click="SendOrder()"
                  ><span>提交订单</span></a
                >
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Address from "@/components/Store/Order/Address";
export default {
  components: {
    Address,
  },
  data() {
    return {
      carts: [],
      cartimg: [],
      nowadd: "",
    };
  },
  methods: {
    SendOrder() {
      if (this.nowadd != "" && this.nowadd != undefined) {
        let time = new Date();
        let buytime =
          time.getFullYear().toString() +
          "/" +
          (time.getMonth() + 1).toString() +
          "/" +
          time.getDate() +
          "  " +
          time.getHours() +
          ":" +
          time.getMinutes() +
          ":" +
          time.getSeconds();
        let orderid = (
          "000000000000" + Math.floor(Math.random() * 99999999999)
        ).slice(-11);
        this.$store.commit("setOrders", {
          cart: this.carts,
          buytime: buytime,
          address: this.nowadd,
          orderid: orderid,
        });
        this.$router.push("/pay");
      } else {
        this.$message({
          type: "warning",
          message: "请添加地址",
        });
      }
    },
  },
  mounted() {
    this.$refs.address.xxxx.then(() => {
      this.$watch(
        () => {
          return this.$refs.address.CurrentAddress[0];
        },
        (val) => {
          this.nowadd = val;
        },
        { immediate: true }
      );
    });
    this.carts = this.$store.getters.getcart;
    if (Object.keys(this.carts).length != 0) {
      this.carts.cart.forEach((e) => {
        this.cartimg.push(e.imgsrc);
      });
    }
  },
};
</script>
<style scoped>
@import url("../../../assets/fa/css/all.css");
@import url("../../../assets/css/base.css");
@import url("../../../assets/css/confirmorder.css");
</style>
